//
//  HZRewardTableViewCell.m
//  Stock_Stategy
//
//  Created by zeroing on 17/6/5.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZRewardTableViewCell.h"

#define kMarging 5
#define kLeftMargin 10

@interface HZRewardTableViewCell()
@property (nonatomic, strong)UILabel *pNameLable;//股票名称
@property (nonatomic, strong)UILabel *pbuyPriceLable;//认购价
@property (nonatomic, strong)UILabel *pbuyContentLable;//200股|1万元
@property (nonatomic, strong)UILabel *pCurPriceLable;//当前价
@property (nonatomic, strong)UILabel *pFenpeiLable;//分配
@property (nonatomic, strong)UILabel *pStatusLable;//执行盈亏
@end

@implementation HZRewardTableViewCell

+ (HZRewardTableViewCell *)cellTableView:(UITableView *)tableView
                                indexPath:(NSIndexPath *)indexPath
                                cellModel:(HZRewardListModel *)cellModel
{
    static NSString *ID = @"rewardListCell";
    HZRewardTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[HZRewardTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        [cell p_commonInit];
    }
    [cell p_updateDataWithmodel:cellModel indexPath:indexPath];
    
    return cell;
}
- (void)p_commonInit
{
    _pNameLable = [UILabel new];
    _pbuyPriceLable = [UILabel new];
    _pbuyContentLable = [UILabel new];
    _pCurPriceLable = [UILabel new];
    _pFenpeiLable = [UILabel new];
    _pStatusLable = [UILabel new];
    
    _pNameLable.font = [UIFont systemFontOfSize:17];
    _pbuyPriceLable.font = _pCurPriceLable.font = [UIFont systemFontOfSize:15];
    _pStatusLable.font = [UIFont systemFontOfSize:11];
    _pbuyContentLable.font = [UIFont systemFontOfSize:11];
    _pFenpeiLable.font = [UIFont systemFontOfSize:11];
    _pNameLable.textAlignment = _pStatusLable.textAlignment = NSTextAlignmentLeft;
    _pbuyPriceLable.textAlignment = _pbuyContentLable.textAlignment = NSTextAlignmentCenter;
    _pCurPriceLable.textAlignment = NSTextAlignmentRight;
    _pFenpeiLable.textAlignment = NSTextAlignmentCenter;
    
    [self.contentView addSubview:_pNameLable];
    [self.contentView addSubview:_pbuyPriceLable];
    [self.contentView addSubview:_pbuyContentLable];
    [self.contentView addSubview:_pCurPriceLable];
    [self.contentView addSubview:_pFenpeiLable];
    [self.contentView addSubview:_pStatusLable];
    
    [self p_initConstraints];
}
- (void)p_initConstraints
{
    [_pNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(kMarging);
        make.left.mas_equalTo(self).offset(kLeftMargin);
        make.bottom.mas_equalTo(_pStatusLable.mas_top);
        make.right.mas_equalTo(_pbuyPriceLable.mas_left);
        make.width.mas_equalTo(self).multipliedBy(0.4);
    }];
    [_pbuyContentLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_pNameLable);
        make.bottom.mas_equalTo(self).offset(-kMarging);
        make.height.mas_equalTo(_pNameLable);
    }];
    [_pbuyPriceLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pNameLable);
        make.left.mas_equalTo(_pNameLable.mas_right);
        make.bottom.mas_equalTo(_pStatusLable.mas_top);
    }];
    [_pStatusLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(_pbuyPriceLable);
        make.bottom.mas_equalTo(self).offset(-kMarging);
        make.height.mas_equalTo(_pbuyPriceLable);
    }];
    [_pCurPriceLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(_pbuyPriceLable);
        make.right.mas_equalTo(self).offset(-kLeftMargin);
        make.width.mas_equalTo(_pbuyPriceLable);
    }];
    [_pFenpeiLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(_pbuyContentLable);
        make.right.mas_equalTo(self).offset(-kLeftMargin);
        make.left.mas_equalTo(_pCurPriceLable);
    }];
}
- (void)p_updateDataWithmodel:(HZRewardListModel *)model indexPath:(NSIndexPath *)indexPath
{
    [self p_cleaOldData];
    [self p_updateNewData:model];
}
- (void)p_updateNewData:(HZRewardListModel *)model
{
    _pNameLable.text = model.model_name;
    _pStatusLable.text = model.model_status;
    _pbuyPriceLable.text = model.model_buyPrice;
    if (model.model_num && model.model_buyMoney) {
        _pbuyContentLable.text = [NSString stringWithFormat:@"%@|%@",model.model_num, model.model_buyMoney];
    }
    _pCurPriceLable.text = model.model_curPrice;
    _pFenpeiLable.text = model.model_perform;
    
    _pbuyPriceLable.hidden = _pbuyContentLable.hidden = _pCurPriceLable.hidden =
    _pFenpeiLable.hidden = NO;
    _pStatusLable.font = [UIFont systemFontOfSize:11];
    _pStatusLable.textColor = [UIColor blackColor];
    [_pNameLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(kMarging);
        make.left.mas_equalTo(self).offset(kLeftMargin);
        make.bottom.mas_equalTo(_pStatusLable.mas_top);
        make.right.mas_equalTo(_pbuyPriceLable.mas_left);
        make.width.mas_equalTo(self).multipliedBy(0.4);
    }];
    [_pStatusLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_pbuyPriceLable);
        make.bottom.mas_equalTo(self).offset(-kMarging);
        make.height.mas_equalTo(_pbuyPriceLable);
    }];
}
- (void)p_cleaOldData{
    [_pNameLable setText:@""];
    [_pStatusLable setText:@""];
    [_pbuyPriceLable setText:@""];
    [_pbuyContentLable setText:@""];
    [_pCurPriceLable setText:@""];
    [_pFenpeiLable setText:@""];
}
@end

